package com.zhoug.zmui3demo.ui;

import android.os.Bundle;
import android.widget.Button;

import com.zhoug.common3.utils.LogUtils;
import com.zhoug.zmui3.ZMUICircleProgress;
import com.zhoug.zmui3demo.R;

import androidx.appcompat.app.AppCompatActivity;

public class ZMUICircleProgressActivity extends AppCompatActivity {
    private static final String TAG = ">>>ZMUICircleProgressActiv";
    private static  boolean debug = false;

    private ZMUICircleProgress mZMUICircleProgress;
    private Button mBtnStart;
    private Button mBtnExchangeMode;

    private int progress = 0;
    private volatile boolean start = false;

    public static void setDebug(boolean debug) {
        ZMUICircleProgressActivity.debug = debug;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zmui_circle_progress);
        findViews();
        mBtnExchangeMode.setOnClickListener(v -> {
            if (mZMUICircleProgress.getMode() == ZMUICircleProgress.MODE_CENTER_TEXT) {
                mZMUICircleProgress.setMode(ZMUICircleProgress.MODE_CENTER_IMAGE);
            } else {
                mZMUICircleProgress.setMode(ZMUICircleProgress.MODE_CENTER_TEXT);
            }
        });
        mZMUICircleProgress.setProgress(50);
        mZMUICircleProgress.setOnProgressListener(new ZMUICircleProgress.OnProgressListener() {
            @Override
            public void onProgress(int progress) {
                if (debug) {
                    LogUtils.d(TAG, "onProgress:progress=" + progress);
                }
            }
        });
        mBtnStart.setOnClickListener(v -> {
            if (start) {
                start = false;
            } else {
                start = true;
                progress = 0;
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        while (start && progress <= 100) {
                            mZMUICircleProgress.setProgress(progress);
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            progress += 10;
                        }
                    }
                }).start();
            }


        });


    }


    private void findViews() {
        mZMUICircleProgress = findViewById(R.id.ZMUICircleProgress);
        mBtnStart = findViewById(R.id.btn_start);
        mBtnExchangeMode = findViewById(R.id.btn_exchangeMode);
    }
}